home *** CD-ROM | disk | FTP | other *** search
/ Amiga Format CD 52 / Amiga Format AFCD52 (Issue 136, May 2000).iso / -serious- / programming / other / whdload / src / whdloadgci / whdloadgci.c < prev    next >
C/C++ Source or Header  |  2000-02-28  |  12KB  |  455 lines

  1. /*****************************************************************************
  2. ;  :Module.        WHDLoadGCI.c
  3. ;  :Author.        Bert Jahn
  4. ;  :EMail.        jah@fh-zwickau.de
  5. ;  :Address.    Franz-Liszt-Straße 16, Rudolstadt, 07404, Germany
  6. ;  :Version.    $Id: WHDloadGCI.c 0.4 1999/01/12 23:58:16 jah Exp jah $
  7. ;  :History.    18.07.98 started
  8. ;                13.12.98 immediate terminate if dump loading fails
  9. ;  :Copyright.    All Rights Reserved
  10. ;  :Language.    C
  11. ;  :Tabsize.    4
  12. ;  :Translator.    SAS 6.58
  13. ****************************************************************************/
  14.  
  15. #include <mui/HexEdit_mcc.h>
  16.  
  17. #include <clib/alib_protos.h>
  18. #include <clib/exec_protos.h>
  19. #include <clib/gadtools_protos.h>
  20. #include <clib/muimaster_protos.h>
  21.  
  22. #include <pragmas/muimaster_pragmas.h>
  23.  
  24. #include <stdio.h>
  25. #include <stdlib.h>
  26.  
  27. #include "whddump.h"
  28. #include "WHDLoadGCI.h"
  29.  
  30. /****************************************************************************/
  31.  
  32. void    make_win_cpu    (void);
  33. void    make_win_cust    (void);
  34.  
  35. void    freedump    (void);
  36. BOOL    loaddump    (STRPTR name);
  37.  
  38. /****************************************************************************/
  39.  
  40. extern struct Library *SysBase,*DOSBase;
  41. struct Library *MUIMasterBase;
  42.  
  43. APTR app,strip,win,
  44.     win_mem=NULL;
  45.  
  46. APTR regmsp,regcacr,regpcr,regbuscr;
  47.  
  48. struct whddump_header    * header = NULL;
  49. struct whddump_cpu        * cpu = NULL;
  50. struct whddump_custom    * custom = NULL;
  51. struct whddump_cia        * ciaa = NULL;
  52. struct whddump_cia        * ciab = NULL;
  53. APTR                    * slave = NULL;
  54. APTR                    * mem = NULL;
  55.  
  56. /****************************************************************************/
  57.  
  58. static VOID fail(APTR app,char *str) {
  59.     if (app) MUI_DisposeObject(app);
  60. #ifndef _DCC
  61.     if (MUIMasterBase) CloseLibrary(MUIMasterBase);
  62. #endif
  63.     if (str) {
  64.         puts(str);
  65.         exit(20);
  66.     }
  67.     exit(0);
  68. }
  69.  
  70. #ifdef _DCC
  71. int brkfunc(void) { return(0); }
  72. int wbmain(struct WBStartup *wb_startup) {
  73.     extern int main(int argc, char *argv[]);
  74.     return (main(0, (char **)wb_startup));
  75. }
  76. #endif
  77.  
  78. #ifdef __SASC
  79. int CXBRK(void) { return(0); }
  80. int _CXBRK(void) { return(0); }
  81. void chkabort(void) {}
  82. #endif
  83.  
  84. static VOID init(VOID) {
  85. #ifdef _DCC
  86.     onbreak(brkfunc);
  87. #endif
  88. #ifndef _DCC
  89.     if (!(MUIMasterBase = OpenLibrary(MUIMASTER_NAME,MUIMASTER_VMIN)))
  90.     fail(NULL,"Failed to open "MUIMASTER_NAME".");
  91. #endif
  92. }
  93.  
  94. /****************************************************************************/
  95.  
  96. struct NewMenu MenuData1[] =
  97. {
  98.     { NM_TITLE, "Project"                    , 0 ,0 ,0             ,(APTR)MEN_PROJECT    },
  99.     { NM_ITEM ,  "About"                    ,"?",0 ,0             ,(APTR)MEN_ABOUT        },
  100.     { NM_ITEM ,  "About MUI"                ,"M",0 ,0             ,(APTR)MEN_ABOUTMUI    },
  101.     { NM_ITEM ,  NM_BARLABEL                , 0 ,0 ,0             ,(APTR)0                },
  102.     { NM_ITEM ,  "Quit"                        ,"Q",0 ,0             ,(APTR)MEN_QUIT        },
  103.  
  104.     { NM_END,NULL,0,0,0,(APTR)0 },
  105. };
  106.  
  107. const char* StringHexAccept = "$0123456789abcdefABCDEF";
  108.  
  109. /*
  110.  *    create string for "String"
  111.  */
  112. STRPTR val2hex4(UWORD val) {
  113.     static char s[6];
  114.     if (val < 16) {
  115.         sprintf(s,"%d",val);
  116.     } else {
  117.         sprintf(s,"$%x",val);
  118.     }
  119.     return s;
  120. }
  121. STRPTR val2hex8(ULONG val) {
  122.     static char s[10];
  123.     if (val < 16) {
  124.         sprintf(s,"%ld",val);
  125.     } else {
  126.         sprintf(s,"$%lx",val);
  127.     }
  128.     return s;
  129. }
  130. /*
  131.  *    create string for "Text"
  132.  */
  133. STRPTR val2hex1t(UBYTE val) {
  134.     static char s[3];
  135.     sprintf(s,"\33r%ld",val);
  136.     return s;
  137. }
  138. STRPTR val2hex4t(UWORD val) {
  139.     static char s[6];
  140.     if (val < 16) {
  141.         sprintf(s,"\33r%d",val);
  142.     } else {
  143.         sprintf(s,"\33r$%x",val);
  144.     }
  145.     return s;
  146. }
  147. STRPTR val2hex8t(ULONG val) {
  148.     static char s[10];
  149.     if (val < 16) {
  150.         sprintf(s,"\33r%ld",val);
  151.     } else {
  152.         sprintf(s,"\33r$%lx",val);
  153.     }
  154.     return s;
  155. }
  156. STRPTR val2hex16t(ULONG val1,ULONG val2) {
  157.     static char s[18];
  158.     if (val1) {
  159.         sprintf(s,"\33r$%lx%08lx",val1,val2);
  160.     } else {
  161.         return val2hex8(val2);
  162.     }
  163.     return s;
  164. }
  165. /*
  166.  *    set contents of "String"
  167.  */
  168. void sethex4(APTR gad, UWORD val) {
  169.     set(gad,MUIA_String_Contents,val2hex4(val));
  170. }
  171. void sethex8(APTR gad, ULONG val) {
  172.     set(gad,MUIA_String_Contents,val2hex8(val));
  173.     set(gad,MUIA_Text_Contents,val2hex8(val));
  174. }
  175. /*
  176.  *    set contents of "Text"
  177.  */
  178. void sethex1t(APTR gad, UBYTE val) {
  179.     set(gad,MUIA_Text_Contents,val2hex1t(val));
  180. }
  181. void sethex4t(APTR gad, UWORD val) {
  182.     set(gad,MUIA_Text_Contents,val2hex4t(val));
  183. }
  184. void sethex8t(APTR gad, ULONG val) {
  185.     set(gad,MUIA_Text_Contents,val2hex8t(val));
  186. }
  187. void sethex16t(APTR gad, ULONG val1, ULONG val2) {
  188.     set(gad,MUIA_Text_Contents,val2hex16t(val1,val2));
  189. }
  190.  
  191. /****************************************************************************/
  192.  
  193. void make_win_mem(int address) {
  194.     ULONG open;
  195.     APTR strip_mem;
  196.     APTR prop, hex;
  197.  
  198.     if (win_mem) {
  199.         get(win_mem,MUIA_Window_Open,&open);
  200.         if (open)    set(win_mem,MUIA_Window_Open,FALSE);
  201.         else        set(win_mem,MUIA_Window_Open,TRUE);
  202.     } else {
  203.         win_mem = WindowObject,
  204.             MUIA_Window_Title, "More Memory",
  205.             MUIA_Window_ID   , MAKE_ID('M','E','M','0'),
  206.             MUIA_Window_Menustrip, strip_mem = MUI_MakeObject(MUIO_MenustripNM,MenuData1,0),
  207.             WindowContents, HGroup,
  208.                 Child, hex = HexEditObject, VirtualFrame,
  209.                     MUIA_HexEdit_LowBound, mem,
  210.                     MUIA_HexEdit_HighBound, ((UBYTE*)mem) + header->wdh_BaseMemSize - 1,
  211.                     MUIA_HexEdit_BaseAddressOffset, -(ULONG)mem,
  212.                     MUIA_HexEdit_EditMode, TRUE,
  213.                     MUIA_HexEdit_SelectMode, MUIV_HexEdit_SelectMode_Byte,
  214.                     MUIA_HexEdit_CursorAddress,address,
  215.                     MUIA_CycleChain, 1,
  216.                     End,
  217.                 Child, prop = ScrollbarObject,
  218.                     MUIA_Prop_UseWinBorder, MUIV_Prop_UseWinBorder_Right,
  219.                     End,
  220.                 End,
  221.             End;
  222.         if (win_mem) {
  223.             DoMethod(app,OM_ADDMEMBER,win_mem);
  224.             set(hex,MUIA_HexEdit_PropObject,prop);
  225.             DoMethod(win_mem,MUIM_Notify,MUIA_Window_CloseRequest,TRUE,app,2,MUIM_Application_ReturnID,MAIN_MOREMEM);
  226.             set(win_mem,MUIA_Window_Open,TRUE);
  227.         } else {
  228.             MUI_Request(app,win,0,NULL,"Ok","Couldn't open Memory window.");
  229.         }
  230.     }
  231. }
  232.  
  233. /****************************************************************************/
  234.  
  235. int main(int argc,char *argv[])
  236. {
  237.     APTR win1;
  238.     APTR
  239.         regd0,regd1,regd2,regd3,regd4,regd5,regd6,regd7,
  240.         rega0,rega1,rega2,rega3,rega4,rega5,rega6,
  241.         regsr,regssp,regusp,regpc,morecpu,
  242.         cudmacon,cuintena,cuintreq,morecust,
  243.         morecias,moremem,
  244.         a_quit,a_restart,a_cont;
  245.     ULONG signals;
  246.     BOOL running = TRUE;
  247.  
  248.     init();
  249.  
  250.     if (argc == 2) loaddump(argv[1]); else loaddump(NULL);
  251.     if (! header) return 20;
  252.  
  253.     printf(
  254.         "BaseMemSize\t%8lx\n"
  255.         "ShadowMem\t%8lx\n"
  256.         "TermReason\t%8lx\n"
  257.         "TermPrimary\t%8lx\n"
  258.         "TermSecondary\t%8lx\n"
  259.         "TermString\t\"%s\"\n"
  260.         "LastBlitPC\t%8lx\n"
  261.         "ExpMemLog\t%8lx\n"
  262.         "ExpMemPhy\t%8lx\n"
  263.         "ExpMemLen\t%8lx\n"
  264.         "ResLoadLog\t%8lx\n"
  265.         "ResLoadPhy\t%8lx\n"
  266.         "ResLoadLen\t%8lx\n"
  267.         "SlaveLog\t%8lx\n"
  268.         "SlavePhy\t%8lx\n"
  269.         "SlaveLen\t%8lx\n"
  270.         "SlaveName\t\"%s\"\n"
  271.         "kn\t\t%8d\n"
  272.         "rw\t\t%8lx\n"
  273.         "cs\t\t%8x\n"
  274.         "CPU\t\t%8x\n"
  275.         "WVer\t\t%8d\n"
  276.         "WRev\t\t%8d\n"
  277.         "WBuild\t\t%8d\n"
  278.         "fc\t\t%8d\n"
  279.         "zpt\t\t%8d\n"
  280.         ,header->wdh_BaseMemSize
  281.         ,header->wdh_ShadowMem
  282.         ,header->wdh_TermReason
  283.         ,header->wdh_TermPrimary
  284.         ,header->wdh_TermSecondary
  285.         ,header->wdh_TermString
  286.         ,header->wdh_LastBlitPC
  287.         ,header->wdh_ExpMemLog
  288.         ,header->wdh_ExpMemPhy
  289.         ,header->wdh_ExpMemLen
  290.         ,header->wdh_ResLoadLog
  291.         ,header->wdh_ResLoadPhy
  292.         ,header->wdh_ResLoadLen
  293.         ,header->wdh_SlaveLog
  294.         ,header->wdh_SlavePhy
  295.         ,header->wdh_SlaveLen
  296.         ,header->wdh_SlaveName
  297.         ,header->wdh_kn
  298.         ,header->wdh_rw
  299.         ,header->wdh_cs
  300.         ,header->wdh_CPU
  301.         ,header->wdh_WVer
  302.         ,header->wdh_WRev
  303.         ,header->wdh_WBuild
  304.         ,header->wdh_fc
  305.         ,header->wdh_zpt
  306.         );
  307.  
  308.     app = ApplicationObject,
  309.         MUIA_Application_Title      , "WHDLoad GCI",
  310.         MUIA_Application_Version    , "$VER: WHDLoad GCI 1.0 (18.07.98)",
  311.         MUIA_Application_Copyright  , "©1998 by Wepl",
  312.         MUIA_Application_Author     , "Wepl",
  313.         MUIA_Application_Description, "WHDload Visualisation and Debugging.",
  314.         MUIA_Application_Base       , "WHDLoadGCI",
  315.         MUIA_Application_Window, win1 = WindowObject,
  316.             MUIA_Window_Title, "WHDLoad GCI",
  317.             MUIA_Window_ID   , MAKE_ID('M','A','I','N'),
  318.             MUIA_Window_Menustrip, strip = MUI_MakeObject(MUIO_MenustripNM,MenuData1,0),
  319.             WindowContents, VGroup,
  320.                 Child, HGroup,
  321.                     Child, HGroup, GroupFrameT("CPU"), MUIA_Group_Columns, 4, MUIA_Weight, 20,
  322.                         Child, Label2("D0:"), Child, regd0 = StringHex8,
  323.                         Child, Label2("A0:"), Child, rega0 = StringHex8,
  324.                         Child, Label2("D1:"), Child, regd1 = StringHex8,
  325.                         Child, Label2("A1:"), Child, rega1 = StringHex8,
  326.                         Child, Label2("D2:"), Child, regd2 = StringHex8,
  327.                         Child, Label2("A2:"), Child, rega2 = StringHex8,
  328.                         Child, Label2("D3:"), Child, regd3 = StringHex8,
  329.                         Child, Label2("A3:"), Child, rega3 = StringHex8,
  330.                         Child, Label2("D4:"), Child, regd4 = StringHex8,
  331.                         Child, Label2("A4:"), Child, rega4 = StringHex8,
  332.                         Child, Label2("D5:"), Child, regd5 = StringHex8,
  333.                         Child, Label2("A5:"), Child, rega5 = StringHex8,
  334.                          Child, Label2("D6:"), Child, regd6 = StringHex8,
  335.                          Child, Label2("A6:"), Child, rega6 = StringHex8,
  336.                          Child, Label2("D7:"), Child, regd7 = StringHex8,
  337.                          Child, Label2("USP:"), Child, regusp = StringHex8,
  338.                         Child, Label2("SR:"), Child, regsr = StringHex4,
  339.                           Child, Label2("SSP:"), Child, regssp = StringHex8,
  340.                           Child, Label2("PC:"), Child, regpc = StringHex8,
  341.                         Child, Label2(""), Child, morecpu = SimpleButton("More"),
  342.                         End,
  343.                     Child, VGroup, MUIA_Weight, 10,
  344.                         Child, VGroup, GroupFrameT("Custom"),
  345.                             Child, HGroup, MUIA_Group_Columns, 2,
  346.                                 Child, Label2("dmacon:"), Child, cudmacon = StringHex4,
  347.                                 Child, Label2("intena:"), Child, cuintena = StringHex4,
  348.                                 Child, Label2("intreq:"), Child, cuintreq = StringHex4,
  349.                                 End,
  350.                             Child, morecust = SimpleButton("More"),
  351.                             End,
  352.                         Child, VGroup, GroupFrameT("Misc"),
  353.                             Child, morecias = SimpleButton("Cia's"),
  354.                             Child, moremem = SimpleButton("Memory"),
  355.                             End,
  356.                         End,
  357.                     End,
  358.                 Child, HGroup, GroupFrameT("Actions"), MUIA_Group_SameWidth, TRUE,
  359.                     Child, a_quit = SimpleButton("Quit"),
  360.                     Child, a_restart = SimpleButton("Restart"),
  361.                     Child, a_cont = SimpleButton("Continue"),
  362.                     End,
  363.                 End,
  364.             End,
  365.         End;
  366.  
  367.     if (!app)
  368.         fail(app,"Failed to create Application.");
  369.  
  370.     win = win1;
  371.  
  372.     DoMethod(win1,MUIM_Notify,MUIA_Window_CloseRequest,TRUE,app,2,MUIM_Application_ReturnID,MUIV_Application_ReturnID_Quit);
  373.  
  374.     DoMethod(morecpu,MUIM_Notify,MUIA_Pressed,FALSE,app,2,MUIM_Application_ReturnID,MAIN_MORECPU);
  375.     DoMethod(morecust,MUIM_Notify,MUIA_Pressed,FALSE,app,2,MUIM_Application_ReturnID,MAIN_MORECUST);
  376.     DoMethod(moremem,MUIM_Notify,MUIA_Pressed,FALSE,app,2,MUIM_Application_ReturnID,MAIN_MOREMEM);
  377.  
  378.     DoMethod(a_quit,MUIM_Notify,MUIA_Pressed,FALSE,app,2,MUIM_Application_ReturnID,MUIV_Application_ReturnID_Quit);
  379.  
  380. /*
  381. ** Input loop...
  382. */
  383.  
  384.     set(win1,MUIA_Window_Open,TRUE);
  385.     
  386.     sethex8(regd0,cpu->wdc_regs[0]);
  387.     sethex8(regd1,cpu->wdc_regs[1]);
  388.     sethex8(regd2,cpu->wdc_regs[2]);
  389.     sethex8(regd3,cpu->wdc_regs[3]);
  390.     sethex8(regd4,cpu->wdc_regs[4]);
  391.     sethex8(regd5,cpu->wdc_regs[5]);
  392.     sethex8(regd6,cpu->wdc_regs[6]);
  393.     sethex8(regd7,cpu->wdc_regs[7]);
  394.     sethex8(rega0,cpu->wdc_regs[8]);
  395.     sethex8(rega1,cpu->wdc_regs[9]);
  396.     sethex8(rega2,cpu->wdc_regs[10]);
  397.     sethex8(rega3,cpu->wdc_regs[11]);
  398.     sethex8(rega4,cpu->wdc_regs[12]);
  399.     sethex8(rega5,cpu->wdc_regs[13]);
  400.     sethex8(rega6,cpu->wdc_regs[14]);
  401.     sethex8(regpc,cpu->wdc_pc);
  402.     sethex4(regsr,cpu->wdc_sr);
  403.     sethex8(regusp,cpu->wdc_usp);
  404.     sethex8(regssp,cpu->wdc_ssp);
  405.     sethex4(cudmacon,custom->wdcu_regs[0x002/2]);
  406.     sethex4(cuintena,custom->wdcu_regs[0x01c/2]);
  407.     sethex4(cuintreq,custom->wdcu_regs[0x01e/2]);
  408.     
  409.     set(cudmacon,MUIA_ShortHelp,"BlitterBusy pine = 0\nAudio 0 = 1");
  410.     
  411.     while (running)
  412.     {
  413.         ULONG id = DoMethod(app,MUIM_Application_Input,&signals);
  414.  
  415.         switch (id)
  416.         {
  417.             case MEN_QUIT:
  418.             case MUIV_Application_ReturnID_Quit:
  419.                 running = FALSE;
  420.                 break;
  421.  
  422.             case MEN_ABOUT:
  423.                 MUI_Request(app,win1,0,NULL,"OK","\33cWHDLoad Graphical Coders Interface\n©1998 Wepl\nAll Rights Reserved.");
  424.                 break;
  425.             case MEN_ABOUTMUI:
  426.                 DoMethod(app,MUIM_Application_AboutMUI,win);
  427.                 break;
  428.  
  429.             case MAIN_MORECPU:
  430.                 make_win_cpu();
  431.                 break;
  432.             case MAIN_MORECUST:
  433.                 make_win_cust();
  434.                 break;
  435.             case MAIN_MOREMEM:
  436.                 make_win_mem(cpu->wdc_pc);
  437.                 break;
  438.  
  439.         }
  440.         if (running && signals) Wait(signals);
  441.     }
  442.  
  443.     set(win1,MUIA_Window_Open,FALSE);
  444.  
  445. /*
  446. ** Shut down...
  447. */
  448.  
  449.     fail(app,NULL);
  450.  
  451.     freedump();
  452.  
  453. }
  454.  
  455.